package com.edu.edu.week_project01.activity.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.edu.edu.week_project01.R;
import com.edu.edu.week_project01.activity.bean.ProgrameLiveDetailBean;

import java.util.List;

/**
 * Created by Administrator on 10/14 0014.
 */
public class RankAdapter extends BaseAdapter{
    private List<ProgrameLiveDetailBean> mlist;

    public RankAdapter(List<ProgrameLiveDetailBean> list){
        this.mlist = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mlist != null ? mlist.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return mlist != null ? mlist.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertview, ViewGroup parent) {
        ViewHolder holder;
        if(convertview == null){
            convertview = LayoutInflater.from(parent.getContext()).inflate(R.layout.second_list_item,parent,false);
            holder = new ViewHolder(convertview);
            convertview.setTag(holder);
        }else{
            holder = (ViewHolder) convertview.getTag();
        }
        //绑定数据
        ProgrameLiveDetailBean bean = mlist.get(position);
        holder.score.setText(bean.getScore());
        holder.send_nick.setText(bean.getSend_nick());
        String icon_url = bean.getIcon_url();
        //利用glide缓存图片
        Glide.with(parent.getContext()).load(icon_url).placeholder(R.mipmap.ic_launcher).into(holder.icon_url);
        return convertview;
    }
    class ViewHolder{
        ImageView icon_url;
        TextView score,send_nick;
        public ViewHolder(View convertview){
            icon_url = (ImageView) convertview.findViewById(R.id.rank_icon_url);
            score = (TextView) convertview.findViewById(R.id.rank_score);
            score = (TextView) convertview.findViewById(R.id.rank_send_nick);
        }
    }
}
